package com.csdj.music.controller;

import com.csdj.music.service.ConsumerService;
import com.csdj.music.vo.Consumer;
import com.csdj.music.vo.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: ConsumerController
 * @Author: ZouLi
 * @Description: 用户控制器
 * @Date: 2023/3/13 15:48
 **/
@RestController
@Api(tags = "用户控制器")
@RequestMapping("/consumer")
public class ConsumerController {

    /**
     * ConsumerService
     **/
    @Autowired
    private ConsumerService consumerService;

    /**
     * @Description: 账号密码登录
     * @Param [username, password, code, request]
     * @Return com.csdj.music.vo.RespBean
     * @Throws
     **/
    @PostMapping("/login")
    @ApiOperation(value = "登录")
    public RespBean login(String username, String password, String code, HttpServletRequest request){
        return consumerService.login(username, password, code, request);
    }

    /**
     * @Description: 手机号登录
     * @Param [phone, code]
     * @Return com.csdj.music.vo.RespBean
     * @Throws
     **/
    @PostMapping("/phoneLogin")
    @ApiOperation(value = "手机号登录")
    public RespBean login(String phone, String code){
        return consumerService.login(phone, code);
    }

    /**
     * @Description: 手机号注册
     * @Param [consumer, code]
     * @Return com.csdj.music.vo.RespBean
     * @Throws
     **/
    @PostMapping("/regist")
    @ApiOperation(value = "注册")
    public RespBean regist(Consumer consumer, String code){
        return consumerService.registConsumer(consumer, code);
    }

    /**
     * @Description: 退出登录
     * @Param []
     * @Return com.csdj.music.vo.RespBean
     * @Throws
     **/
    @PostMapping
    @ApiOperation(value = "退出登录")
    public RespBean logout(){
        return RespBean.success("退出成功！已为您自动跳转至登录页面~");
    }
}
